package base.thread.pool;

import java.util.concurrent.*;

/**
 * @Author: my_code
 * @Create: 2020-12-06 22:16
 *
 *
 */
public class TestPool2 implements Callable<Boolean> {

    @Override
    public Boolean call() throws Exception {
        System.out.println("Callable创建线程:"+Thread.currentThread().toString());
        return true;
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        TestPool2 t1 = new TestPool2();
        TestPool2 t2 = new TestPool2();
        //创建执行服务
        ExecutorService ser = Executors.newFixedThreadPool(2);
        //提交执行
        Future<Boolean> submit1 = ser.submit(t1);
        Future<Boolean> submit2 = ser.submit(t2);
        //获取结果
        Boolean rs1 = submit1.get();
        Boolean rs2 = submit2.get();
        //关闭服务
        ser.shutdown();
    }
}
